package com.tuniu.agents.tools.flights;

import com.tuniu.agents.tools.flights.domestic.oneway.FlightInformationQueryTool;
import com.tuniu.agents.tools.flights.domestic.oneway.FlightLowPriceQueryTool;
import com.tuniu.agents.tools.flights.domestic.oneway.FlightTimeQueryTool;
import com.tuniu.agents.tools.flights.domestic.oneway.FlightTransferQueryTool;
import com.tuniu.agents.tools.flights.domestic.roundtrip.RoundFlightInformationQueryTool;
import com.tuniu.agents.tools.flights.domestic.roundtrip.RoundFlightLowPriceQueryTool;
import com.tuniu.agents.tools.flights.international.oneway.IntlFlightInformationQueryTool;
import com.tuniu.agents.tools.flights.international.oneway.IntlFlightLowPriceQueryTool;
import com.tuniu.agents.tools.flights.international.oneway.IntlFlightTransferQueryTool;
import com.tuniu.agents.tools.flights.international.roundtrip.IntlRoundFlightInformationQueryTool;
import com.tuniu.agents.tools.flights.international.roundtrip.IntlRoundFlightLowPriceQueryTool;
import com.tuniu.agents.tools.flights.utils.CityCodeUtils;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;

@Configuration
@EnableConfigurationProperties(FlightProperties.class)
@ConditionalOnClass(FlightProperties.class)
@ConditionalOnProperty(prefix = "aigc.agents.tools.flight", name = "enabled", havingValue = "true")
public class FlightAutoConfiguration {

    @Bean
    public CityCodeUtils cityCodeUtils(FlightProperties properties){
        return new CityCodeUtils(properties);
    }

    @Bean(FlightInformationQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("国内机票单程最便宜航班详情查询")
    @Tool(returnDirect = true)
    public FlightInformationQueryTool queryFlightInformation(FlightProperties properties) {
        return new FlightInformationQueryTool(properties);
    }

    @Bean(FlightLowPriceQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("Find the cheapest one-way domestic flights")
    @Tool(returnDirect = true)
    public FlightLowPriceQueryTool queryFlightLowPrice(FlightProperties properties) {
        return new FlightLowPriceQueryTool(properties);
    }

    @Bean(FlightTransferQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("Find the fastest domestic one-way flights with connections")
    @Tool(returnDirect = true)
    public FlightTransferQueryTool queryFlightTransfer(FlightProperties properties) {
        return new FlightTransferQueryTool(properties);
    }

    @Bean(FlightTimeQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("Query domestic flights by time range")
    @Tool(returnDirect = true)
    public FlightTimeQueryTool queryFlightTime(FlightProperties properties) {
        return new FlightTimeQueryTool(properties);
    }

    @Bean(RoundFlightInformationQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("国内机票往返最便宜航班详情查询")
    @Tool(returnDirect = true)
    public RoundFlightInformationQueryTool queryRoundFlightInformation(FlightProperties properties) {
        return new RoundFlightInformationQueryTool(properties);
    }

    @Bean(RoundFlightLowPriceQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("Find the cheapest round-trip domestic flights")
    @Tool(returnDirect = true)
    public RoundFlightLowPriceQueryTool queryRoundLowPrice(FlightProperties properties) {
        return new RoundFlightLowPriceQueryTool(properties);
    }


    @Bean(IntlFlightInformationQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("Query international one-way flight ticket details（When the user explicitly wants to book/query a flight, call this tool）")
    @Tool(returnDirect = true)
    public IntlFlightInformationQueryTool queryIntFlightInformation(FlightProperties properties) {
        return new IntlFlightInformationQueryTool(properties);
    }

    @Bean(IntlFlightLowPriceQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("Query for the lowest-priced one-way international flight ticket")
    @Tool(returnDirect = true)
    public IntlFlightLowPriceQueryTool queryIntFlightLowPrice(FlightProperties properties) {
        return new IntlFlightLowPriceQueryTool(properties);
    }

    @Bean(IntlFlightTransferQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("Query for the fastest connecting one-way international flight ticket")
    @Tool(returnDirect = true)
    public IntlFlightTransferQueryTool queryIntFlightTransfer(FlightProperties properties) {
        return new IntlFlightTransferQueryTool(properties);
    }


    @Bean(IntlRoundFlightInformationQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("Query international round-trip flight ticket details")
    @Tool(returnDirect = true)
    public IntlRoundFlightInformationQueryTool queryIntRoundFlightInformation(FlightProperties properties) {
        return new IntlRoundFlightInformationQueryTool(properties);
    }

    @Bean(IntlRoundFlightLowPriceQueryTool.TOOLNAME)
    @ConditionalOnMissingBean
    @Description("Query for the lowest-priced round-trip international flight ticket")
    @Tool(returnDirect = true)
    public IntlRoundFlightLowPriceQueryTool queryIntRoundLowPrice(FlightProperties properties) {
        return new IntlRoundFlightLowPriceQueryTool(properties);
    }
}
